package com.seafwg.store.service.impl;

import com.seafwg.store.entity.District;
import com.seafwg.store.mapper.DistrictMapper;
import com.seafwg.store.service.IDistrictService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author seafwg
 * @Date 2022/4/1 10:52 下午
 * @Version 1.0
 * @description xxx
 */
@Service
public class DistrictServiceImpl implements IDistrictService {

    @Resource
    private DistrictMapper districtMapper;

    /**
     * 获取省市区县的集合
     * @param parent 上一级code值
     * @return
     */
    @Override
    public List<District> getDistrictByParent(String parent) {
        List<District> list = districtMapper.findDistrictByParent(parent);
        // 不用的数据制空
        for (District district : list) {
            district.setParent(null);
            district.setId(null);
        }
        return list;
    }

    /**
     * 查询省市区县编码code对应的名称
     * @param code 当前code
     * @return
     */
    @Override
    public String getNameByCode(String code) {
        return districtMapper.findDistrictNameByCode(code);
    }
}
